#ifndef _KRAW_MATH_H_
#define _KRAW_MATH_H_

//Humus framework classes
#include "Math/Vector.h"

// These classes are not intended to implement a math library,
// just a convenient representation that can be consistently
// used across the framework
namespace Kraw
{
typedef	vec2 vector2;
typedef vec3 vector3;
typedef vec4 Vector4;

typedef mat3 matrix33;
typedef mat4 matrix44;

//in DirectX (fixed function)
inline matrix44 lookAtLh(const vector3& eye, const vector3& at, const vector3& up)
{
	vector3 zaxis = normalize(at - eye);
	vector3 xaxis = normalize(cross(up, zaxis));
	vector3 yaxis = cross(zaxis, xaxis);

	return matrix44( xaxis.x, yaxis.x, zaxis.x, 0.f, 
					  xaxis.y, yaxis.y, zaxis.y, 0.f, 
					  xaxis.z, yaxis.z, zaxis.z, 0.f, 
					  -dot(xaxis, eye), -dot(yaxis, eye), -dot(zaxis, eye),   1.f );
}

//in OpenGL
inline matrix44 lookAtRh(const vector3& eye, const vector3& at, const vector3& up)
{
	vector3 zaxis = eye - at;
	normalize(zaxis);
	vector3 xaxis = cross(up, zaxis);
	normalize(xaxis);
	vector3 yaxis = cross(zaxis, xaxis);

	return matrix44( xaxis.x, yaxis.x, zaxis.x, 0.f, 
					  xaxis.y, yaxis.y, zaxis.y, 0.f, 
					  xaxis.z, yaxis.z, zaxis.z, 0.f, 
					  eye.x,   eye.y,   eye.z,   1.f );
}

inline matrix44 perspectiveFovLh(const float fov, const float aspect, const float zNear, const float zFar)
{
	float h = cosf(0.5f * fov) / sinf(0.5f * fov);
	float w = h / aspect;

	return mat4( w, 0, 0, 0,
				 0, h, 0, 0,
				 0, 0, zFar / (zFar - zNear), 1.f,
				 0, 0, -zNear * (zFar / (zFar - zNear)), 0 );
}

struct Quaternion
{
public:
    Quaternion() {}
	Quaternion(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; }

	float x, y, z, w;
};
}

#endif //_KRAW_MATH_H_
